package com.escom.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.escom.R;
import com.escom.healthlc.entidad.OximetroORM;
import com.escom.service.OximetroService;
import com.escom.utils.CustomOximetroAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 * Created by Carlos on 20/04/2014.
 */
public class OximetroFragment extends Fragment {

    private ListView listViewOximetro;
    private CustomOximetroAdapter customOximetroAdapter;
    //private static Thread tareaOximetro;

    private class OximetroObservador implements Observer {

        @Override
        public void update(Observable o, Object arg) {
            customOximetroAdapter.notifyDataSetChanged();
        }
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View viewActivity = inflater.inflate(R.layout.fragment_oximetro, container, false);

        listViewOximetro = (ListView) viewActivity.findViewById(R.id.listViewOximetro);
        List<OximetroORM> oximetroList = new ArrayList<OximetroORM>();
        customOximetroAdapter = new CustomOximetroAdapter(viewActivity.getContext(), R.layout.custom_oximetro_item, oximetroList);
        listViewOximetro.setAdapter(customOximetroAdapter);

        OximetroObservador oximetroObservador = new OximetroObservador();
        OximetroService oximetroService = new OximetroService(customOximetroAdapter, getActivity(),oximetroList);
        oximetroService.addObserver(oximetroObservador);

        Thread tareaOximetro = new Thread(oximetroService);
        tareaOximetro.start();

        return viewActivity;
    }

}
